home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / misc / bioz2.lha / BioZ_II / BioZII.c < prev    next >
C/C++ Source or Header  |  1992-12-04  |  20KB  |  831 lines

  1. /* Lc BioZII
  2. Blink from lib:c.o+bioZII.o LIB lib:lcm.lib lib:lc.lib lib:amiga.lib to RAM:BioZII DEFINE __main=__tinymain NODEBUG SMALLDATA SMALLCODE VERBOSE */
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <graphics/gfxbase.h>
  9. #include <exec/devices.h>
  10. #include <exec/memory.h>
  11. #include <devices/printer.h>
  12. #include <devices/prtbase.h>
  13. #include <workbench/workbench.h>
  14. #include <workbench/icon.h>
  15. #include <workbench/startup.h>
  16. #include "ram:BioZReq.c"
  17.  
  18.  
  19. #define bisex(x) ((x%4)==0)
  20. #define pi ((float) 3.141593)
  21.  
  22. UBYTE vers[]="\0$VER: BioZII v1.1 (17.06.93)";
  23. int hauteur[2]={256,200},Axe[2]={100,90},comm[2]={180,150},comm2[2]={20,14},
  24.     comm3[2]={190,155},amp[2]={50,45};
  25.  
  26. struct IntuitionBase *IntuitionBase;
  27. struct GfxBase *GfxBase;
  28. struct Window *Window;
  29. struct Screen *Screen, *WBScreen;
  30. struct IconBase *IconBase=NULL;
  31.  
  32. struct IntuiMessage *Message;
  33. struct RastPort *RPort;
  34. struct DiskObject *DiskObj=0;
  35.  
  36. int hardcopy();
  37.  
  38. char *inter[3][3][3][3],*probleme=NULL,name[100],*fichier=NULL,
  39.      *phy=NULL,*emo=NULL,*cer=NULL,*MyMsg=NULL,*Mess[2]={NULL,NULL},
  40.      *azaaz=NULL,*bio=NULL;
  41. int j[3],m[3],a[3],axe=100,lar=20,mois[13]={31,28,31,30,31,30,31,31,30,31,30,31};
  42. int jv,ph[3],em[3],ce[3],MyErr=0,mode=0;
  43.  
  44. BOOL DMReq=FALSE,First=TRUE,Date=FALSE;
  45.  
  46. char *fill(ch2,n,m)
  47. char *ch2;
  48. int n;
  49. {
  50.     char *ch;
  51.     ch=(char*)malloc(n+m);
  52.     stccpy(ch,ch2,n);
  53.     return(ch);
  54. }
  55.     
  56. void LoadComment()
  57. {
  58.     int i,j,k,l;
  59.     char a[80],*m;
  60.     FILE *MyFile;
  61.     
  62.     MyFile=fopen(fichier,"r");
  63.  
  64.     for(i=0;i<=17;i+=1)
  65.     {
  66.         if(MyFile==NULL) m=NULL; else m=fgets(a,sizeof(a),MyFile);
  67.         if(m!=NULL)
  68.         {
  69.             switch(i)
  70.             {
  71.                 case 0 : NewScreen.DefaultTitle=fill(a,min(strlen(a),77),0);                     
  72.                      break;
  73.                 case 1 : NewWindow.Title=fill(a,min(strlen(a),74),0);
  74.                      break;
  75.                 case 2 : bio=fill(a,min(strlen(a),35),1);
  76.                      strcat(bio," ");
  77.                      break;
  78.                 case 3 : azaaz=fill(a,min(strlen(a),11),1);
  79.                      strcat(azaaz," ");
  80.                      break; 
  81.                 case 4 : phy=fill(a,min(strlen(a),16),0);
  82.                      break;
  83.                 case 5 : emo=fill(a,min(strlen(a),16),0);
  84.                      break;
  85.                 case 6 : cer=fill(a,min(strlen(a),16),0);
  86.                      break;
  87.                 case 7 : IText7.IText=fill(a,min(strlen(a),23),0);
  88.                      break;
  89.                 case 8 : IText6.IText=fill(a,min(strlen(a),23),0);
  90.                      break;
  91.                 case 9 : Mess[0]=fill(a,min(strlen(a),73),0);
  92.                      break;
  93.                 case 10: Mess[1]=fill(a,min(strlen(a),73),0);
  94.                      break;
  95.                 case 11: probleme=fill(a,min(strlen(a),77),0);  
  96.                      break;
  97.                 case 12: MyMsg=fill(a,min(strlen(a),73)),0;
  98.                      break;
  99.                 case 13: IText8.IText=fill(a,min(strlen(a),6),0);
  100.                      IText8.LeftEdge-=4*(strlen(a)-5);
  101.                      break;
  102.                 case 14: IText4.IText=fill(a,min(strlen(a),11),0);
  103.                      IText4.LeftEdge=(92-7*strlen(a))/2;
  104.                      break;
  105.                 case 15: IText5.IText=fill(a,min(strlen(a),16),0);
  106.                      break;
  107.                 case 16: if(Gadget4SInfo.Buffer==NULL) Gadget4SInfo.Buffer=fill(a,9,0);
  108.                      Gadget4SInfo.UndoBuffer=fill(a,9,0);
  109.                      break;
  110.                 case 17: IText20.IText=fill(a,min(strlen(a),20),0);
  111.                      break;
  112.             }
  113.         }
  114.     }
  115.  
  116.     if(Mess[0]==NULL) Mess[0]="Date de prédiction invalide !";
  117.     if(Mess[1]==NULL) Mess[1]="Date de naissance invalide !";
  118.     if(NewScreen.DefaultTitle==NULL) NewScreen.DefaultTitle="BioZ II v1.1     créé par Mikaël ZAJAC        mis à jour le 17/06/93";
  119.     if(NewWindow.Title==NULL) NewWindow.Title="Biorythmes";
  120.     if(bio==NULL) bio="Biorythmes du ";
  121.     if(azaaz==NULL) azaaz=" né(e) le ";
  122.     if(phy==NULL) phy="Physique";
  123.     if(emo==NULL) emo="Emotionnel";
  124.     if(cer==NULL) cer="Cérébral";
  125.     if(IText7.IText==NULL) IText7.IText="Date de prédiction :";
  126.     if(IText6.IText==NULL) IText6.IText="Date de naissance : ";
  127.     if(Mess[0]==NULL) Mess[0]="Date de prédiction invalide !";
  128.     if(Mess[1]==NULL) Mess[1]="Date de naissance invalide !";
  129.     if(probleme==NULL) probleme="      Commentaire introuvable !";
  130.     if(MyMsg==NULL) MyMsg="Erreur d'acces à l'Imprimante";
  131.     if(IText8.IText==NULL) IText8.IText="Mois";
  132.     if(IText4.IText==NULL) IText4.IText="Imprimer";
  133.     if(IText5.IText==NULL) IText5.IText="Prénom et Nom :";
  134.     if(Gadget4SInfo.Buffer==NULL) Gadget4SInfo.Buffer="jj/mm/aa";
  135.     if(Gadget4SInfo.UndoBuffer==NULL) Gadget4SInfo.UndoBuffer="jj/mm/aa";
  136.     if(IText20.IText==NULL) IText20.IText="Impression en cours...";
  137.  
  138.     for(i=0;i<=2;i+=1)
  139.         for(j=0;j<=2;j+=1)
  140.             for(k=0;k<=2;k+=1)
  141.                 for(l=0;l<=2;l+=1)
  142.                 {
  143.                     if(MyFile==NULL) m=NULL; else m=fgets(a,sizeof(a),MyFile);
  144.                     if(m!=NULL)
  145.                     {
  146.                         inter[i][j][k][l]=fill(a,min(strlen(a),77),0);
  147.                     }
  148.                     else if(l==0) inter[i][j][k][l]=probleme; else inter[i][j][k][l]="";
  149.                 }
  150.     
  151.     fclose(MyFile);
  152. }
  153.  
  154. void swap(x,y)
  155. int *x,*y;
  156. {
  157.     int z;
  158.     z=*x;
  159.     *x=*y;
  160.     *y=z;
  161. }
  162.  
  163. char *search(aa)
  164. char *aa;
  165. {
  166.     int i=0;
  167.     while(aa[i++]!='|') if(i>strlen(aa)) break;
  168.     if(i>strlen(aa)) return(NULL); else  return(&aa[i]);
  169. }
  170.  
  171. float Nom()
  172. {
  173.     char *Value=0;
  174.     if(IconBase!=NULL && (DiskObj!=0 && strlen(Gadget2SIBuff)>=1))
  175.     {
  176.         Value=FindToolType(DiskObj->do_ToolTypes,Gadget2SIBuff);
  177.         if(Value!=0)
  178.         {
  179.             free(Gadget4SInfo.Buffer);
  180.             Gadget4SInfo.Buffer=fill(Value,9,0);
  181.             if(search(Value)!=NULL) stccpy(Gadget2SIBuff,search(Value));
  182.         }
  183.     }
  184.     if(Value!=0) return(1); else return(0);
  185. }
  186.  
  187. void Args()
  188. {
  189.     char *Value;
  190.     IconBase=(struct IconBase *)OpenLibrary(ICONNAME,0);
  191.     if(IconBase!=NULL)
  192.     {
  193.         DiskObj=GetDiskObject(name);
  194.         if(DiskObj!=0)
  195.         {
  196. /*            Value=FindToolType(DiskObj->do_ToolTypes,"MONITOR");
  197.             if(MatchToolValue(Value,"NTSC")) mode=1; */
  198.             Value=FindToolType(DiskObj->do_ToolTypes,"DATE");
  199.             if(MatchToolValue(Value,"USA")) Date=TRUE;
  200.             Value=FindToolType(DiskObj->do_ToolTypes,"START");
  201.             if(Value!=0)
  202.             {
  203.                 strncpy(Gadget2SIBuff,Value,min(strlen(Value),24));
  204.                 Value=FindToolType(DiskObj->do_ToolTypes,Gadget2SIBuff);
  205.                 if(Value!=0)
  206.                 {
  207.                     free(Gadget4SInfo.Buffer);
  208.                     Gadget4SInfo.Buffer=fill(Value,9,0);
  209.                     if(search(Value)!=NULL) stccpy(Gadget2SIBuff,search(Value));
  210.                 }
  211.             }
  212.             Value=FindToolType(DiskObj->do_ToolTypes,"FILE");
  213.             if(Value!=0 && fichier==NULL)
  214.             {
  215.                 fichier=(char*)malloc(strlen(Value)+1);
  216.                 strcpy(fichier,Value);
  217.             }
  218.         }
  219.         if(fichier==NULL)
  220.         {
  221.             fichier=(char*)malloc(9);
  222.             strcpy(fichier,"français");
  223.         }
  224.     }
  225. }
  226.     
  227.  
  228. void colors(col)
  229. int col;
  230. {
  231.     USHORT cmap[3][8]={ {0x0AAA,0x0000,0x0FFF,0x000F,0x0F0F,0x0FF0,0x0000,0x0F00 },
  232.                 {0x0FFF,0x0000,0x0FFF,0x00FF,0x0F0F,0x00F0,0x0000,0x0F00 },
  233.                 {0x0FFF,0x0000,0x0FFF,0x0000,0x0000,0x0000,0x0000,0x0F00 }};
  234.     LoadRGB4(&Screen->ViewPort,&cmap[col],8);
  235. }
  236.  
  237. int init()
  238. {
  239.     LoadComment();
  240.     if((IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0))==NULL) return(0);
  241.     if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL) return(1);
  242.     if( GfxBase->DisplayFlags & NTSC ) mode=1;
  243.     axe=Axe[mode];
  244.     NewScreen.Height=hauteur[mode];
  245.     if((Screen=(struct Screen *) OpenScreen(&NewScreen))==NULL) return(2);
  246.     NewWindow.Screen=Screen;
  247.     NewWindow.Height=hauteur[mode]-12;
  248.     if((Window=(struct Window *)OpenWindow(&NewWindow))==NULL) return(3);
  249.     RPort=Window->RPort;
  250.     colors(0);
  251.     MyReq.TopEdge=(hauteur[mode]-24-MyReq.Height)/2;
  252.     MyReq2.TopEdge=(hauteur[mode]-24-MyReq2.Height)/2;
  253.     if(!Request(&MyReq,Window)) return(4);
  254.     return(-1);
  255. }
  256.  
  257. void cleanup(l)
  258. int l;
  259. {
  260.     switch(l)
  261.     {
  262.         case 4:    CloseWindow(Window);
  263.         case 3:    CloseScreen(Screen);
  264.         case 2:    CloseLibrary(GfxBase);
  265.         case 1:    CloseLibrary(IntuitionBase);
  266.         case 0: exit(0);
  267.             break;
  268.     }
  269. }
  270.  
  271. void sdate(to,day,month,year)
  272. int day,month,year;
  273. char to[9];
  274. {
  275.     int i;
  276.     if(Date) sprintf(to,"%2d/%2d/%2d",month,day,year);
  277.     else     sprintf(to,"%2d/%2d/%2d",day,month,year);
  278.     for(i=0;i<=9;i++)
  279.         if(to[i]==' ') to[i]='0';
  280. }
  281.     
  282.     
  283.  
  284. int strdate(ch,ch2,x,y)
  285. int x,y;
  286. char *ch2,ch[9];
  287. {
  288.     char *ch3;
  289.     sdate(Gadget3SIBuff,j[1],m[1],a[1]);
  290.     SetAPen(RPort,1);
  291.     ch3=(char *)malloc(strlen(ch2)+strlen(ch)+1);
  292.     strcpy(ch3,ch2);
  293.     strcat(ch3,ch);
  294.     Move(RPort,x,y);
  295.     Text(RPort,ch3,strlen(ch3));
  296.     free(ch3);
  297.     return(0);
  298. }
  299.  
  300. void Chemin(L)
  301. BPTR L;
  302. {
  303.     struct FileInfoBlock Block;
  304.     if(ParentDir(L)!=NULL)
  305.         Chemin(ParentDir(L));
  306.  
  307.     if(Examine(L,&Block))
  308.     {
  309.         strcat(fichier,Block.fib_FileName);
  310.         if(ParentDir(L)==NULL)
  311.             strcat(fichier,":");
  312.         else
  313.             strcat(fichier,"/");
  314.     }
  315. }
  316.  
  317. main(argc,argv)
  318. int argc;
  319. char **argv;
  320. {
  321.     int val=1;
  322.     struct WBStartup *msg;
  323.     
  324.     if(argc!=0)
  325.         strcpy(name,argv[0]);
  326.     else
  327.     {
  328.         msg=(struct WBStartup *) argv;
  329.         strcpy(name,msg->sm_ArgList[0].wa_Name);
  330.         if(msg->sm_NumArgs==2)
  331.         {
  332.             fichier=(char*)malloc(300);
  333.             Chemin(msg->sm_ArgList[1].wa_Lock);
  334.             strcat(fichier,msg->sm_ArgList[1].wa_Name);
  335.         }
  336.  
  337.     }
  338.         
  339.     if(argc==2)
  340.     {
  341.         fichier=(char*)malloc(strlen(argv[1])+1);
  342.         strcpy(fichier,argv[1]);
  343.     }
  344.  
  345.  
  346.     Args();
  347.     dates();
  348.     cleanup(init());
  349.     fin();
  350.     plmo:
  351.     if(val==1)
  352.     {
  353.         SetAPen(RPort,0);
  354.         RectFill(RPort,7,22,635,hauteur[mode]-16);
  355.         joursvecus(1,j[1]);
  356.         joursvecus(2,1);
  357.         dessine();
  358.     }
  359.     if((val=fin())!=0) goto plmo;    
  360.     if(argc==0 && msg->sm_NumArgs==2) free(fichier);
  361. }
  362.  
  363. int dates()
  364. {
  365.     char d[8];
  366.     getclk(d);
  367.     sdate(Gadget3SIBuff,d[3],d[2],d[1]+80);
  368.     a[1]=d[1]+80;
  369.     m[1] = d[2];
  370.     j[1] = d[3];
  371.     return(0);
  372. }
  373.     
  374. void dates2()
  375. {
  376.     char *pn=NULL;
  377.     pn=fill(Gadget2SIBuff,strlen(Gadget2SIBuff)+1,strlen(azaaz)+1);
  378.     if(strlen(Gadget2SIBuff)<1)
  379.     {
  380.         free(pn);
  381.         pn=fill(IText6.IText,strlen(IText6.IText)+1,2);
  382.         strcat(pn," ");
  383.     }
  384.     else
  385.         strcat(pn,azaaz);
  386.     SetAPen(RPort,0);
  387.     RectFill(RPort,7,12,635,22);
  388.     strdate(Gadget4SInfo.Buffer,pn,10,19);
  389.     free(pn);
  390.     pn=NULL;
  391.     Move(RPort,350,19);
  392.     SetAPen(RPort,3);
  393.     Text(RPort,phy,strlen(phy));
  394.     Move(RPort,500,19);
  395.     SetAPen(RPort,5);
  396.     Text(RPort,emo,strlen(emo));
  397. }
  398.  
  399. int joursvecus(c,day)
  400. int c,day;
  401. {
  402.     int za,av,mv,mm=0,ab=0,mmm=0;
  403.     av=(a[1]-1-a[2])*365;
  404.     for(mv=m[2];mv<=12;mv++)
  405.         mm+=mois[mv];
  406.     for(mv=m[1]-1;mv>=1;mv--)
  407.         mmm+=mois[mv-1];
  408.     av+=(mois[m[2]-1]-j[2]);
  409.     for(za=a[2]+1;za<a[1];za++)
  410.         if (bisex(za)) ab++; 
  411.     if ( m[2]<3 && bisex(a[2])) ab++;
  412.     if ( m[1]>2 && bisex(a[1])) ab++;
  413.     jv=av+mm+mmm+ab+day;
  414.     ph[c]=jv%23;
  415.     em[c]=jv%28;
  416.     ce[c]=jv%33;
  417.     return(jv);
  418. }
  419.  
  420. int dessine()
  421. {
  422.     int i,n;
  423.     char z[3]="";
  424.     
  425.     if(m[1]==2 && bisex(a[1])) mois[m[1]-1]=29;
  426.     lar=620-620%mois[m[1]-1];
  427.     
  428.     SetAPen(RPort,1);
  429.     Move(RPort,10,axe);
  430.     Draw(RPort,lar+10,axe);
  431.     
  432.     for(i=0;i<=mois[m[1]-1];i++)
  433.     {    
  434.         n=i/2;
  435.         SetAPen(RPort,1);
  436.         Move(RPort,(lar/mois[m[1]-1])*i+10,axe-3);
  437.         Draw(RPort,(lar/mois[m[1]-1])*i+10,axe+3);
  438.         if(i<mois[m[1]-1])
  439.         {
  440.             if(i==n*2) Move(RPort,(lar/mois[m[1]-1])*i+13,axe-3);
  441.             else       Move(RPort,(lar/mois[m[1]-1])*i+13,axe+9);
  442.             sprintf(z,"%2d",i+1);
  443.             if(z[0]==' ') z[0]='0';
  444.             Text(RPort,z,2);
  445.         }
  446.     }
  447.     
  448.     sinusoide(ph[2],23,1);
  449.     sinusoide(em[2],28,3);
  450.     sinusoide(ce[2],33,2);
  451.     
  452.     SetAPen(RPort,1);
  453.     Move(RPort,(j[1]*lar/mois[m[1]-1])+10-((lar/mois[m[1]-1])/2),axe-amp[mode]-5);
  454.     Draw(RPort,(j[1]*lar/mois[m[1]-1])+10-((lar/mois[m[1]-1])/2),axe+amp[mode]+5);
  455.     Move(RPort,425,29);
  456.     SetAPen(RPort,4);
  457.     Text(RPort,cer,strlen(cer));
  458.     strdate(&Gadget3SIBuff,bio,10,29);
  459.         
  460.     interpretation();
  461.     mois[1]=28;
  462.     return(0);
  463. }
  464.  
  465. void verif()
  466. {
  467.     if (j[1]>29 && m[1]==2 && bisex(a[1])) j[1]=29;
  468.     if (j[1]>mois[m[1]-1] && (m[1]!=2 || !bisex(a[1]))) 
  469.         j[1]=mois[m[1]-1];
  470. }
  471.  
  472. int fin()
  473. {
  474.     int Code,i,jj,mm,aa;
  475.     long Class;
  476.     float k;
  477.     APTR Adresse;    
  478.  
  479.     wxt:
  480.     Wait(1<<Window->UserPort->mp_SigBit);
  481.     while(Message=(struct IntuiMessage *)GetMsg(Window->UserPort))
  482.     {
  483.         Class=Message->Class;
  484.         Code=Message->Code;
  485.         Adresse=Message->IAddress;
  486.         ReplyMsg(Message);
  487.         switch(Class)
  488.         {
  489.             case REQSET:
  490.                 ActivateGadget(&Gadget2,Window,&MyReq);
  491.                 break;
  492.             case GADGETUP:
  493.                 k=0;
  494.                 if(Adresse==(APTR)&Gadget2) k=(float) Nom();
  495.                 i=sscanf(Gadget3SIBuff,"%d%*c%d%*c%d",&j[1],&m[1],&a[1]);
  496.                 if(Date) swap(&j[1],&m[1]);
  497.                 if( i!= 5 || (j[1]>mois[m[1]-1] &&  (m[1]!=2 || !bisex(a[1])))
  498.                     || m[1]>13 || m[1]<1 || j[1]<1 ||
  499.                     (m[1]==2 && bisex(a[1]) && j[1]>29))
  500.                     MyErr=1;
  501.                 
  502.                 i=sscanf(Gadget4SInfo.Buffer,"%d%*c%d%*c%d",&j[2],&m[2],&a[2]);
  503.                 if(Date) swap(&j[2],&m[2]);
  504.                 if ( i!= 5 || (j[2]>mois[m[2]-1] &&  (m[2]!=2 || bisex(a[2])))
  505.                     || m[2]>13 || m[2]<1 || j[2]<1 ||
  506.                     (m[2]==2 && bisex(a[2]) && j[2]>29))
  507.                     MyErr=2;
  508.                 else
  509.                     if(j[1]+100*m[1]+10000*a[1]<j[2]+100*m[2]+10000*a[2])
  510.                         MyErr=1;
  511.                     else
  512.                         sdate(Gadget4SInfo.Buffer,j[2],m[2],a[2]);
  513.                 if(Adresse==(APTR)&Gadget2 && k==0) ActivateGadget(&Gadget4,Window,&MyReq);
  514.                 if(k==1) RefreshGadgets(&Gadget4,Window,&MyReq);
  515.                 if(Adresse==(APTR)&Gadget4 || k==1) ActivateGadget(&Gadget3,Window,&MyReq);
  516.     
  517.                 if(!DMReq) DMReq=SetDMRequest(Window,&MyReq);
  518.                 if(Adresse==(APTR)&Gadget5 || Adresse==(APTR)&Gadget6 || Adresse==(APTR)&Gadget7 || Adresse==(APTR)&Gadget1)
  519.                     if(MyErr!=0)
  520.                     {
  521.                         BAD.IText=&Mess[MyErr-1][0];
  522.                         if(MyErr==1) strcpy(&Gadget3SIBuff,&UNDOBUFFER2);
  523.                         else strcpy(Gadget4SInfo.Buffer,Gadget4SInfo.UndoBuffer);
  524.                         MyErr=0;
  525.                         if(DMReq)
  526.                         {
  527.                             ClearDMRequest(Window);
  528.                             DMReq=FALSE;
  529.                         }
  530.                         AutoRequest(Window, &BAD, NULL, &OK, NULL, NULL, 320, 72);
  531.                         Request(&MyReq,Window);
  532.                     }
  533.                     else
  534.                     {
  535.                         
  536.                         if(Adresse==(APTR)&Gadget5)
  537.                         {
  538.                             mplus();
  539.                             verif();
  540.                             dates2();
  541.                             RefreshGadgets(&Gadget3,Window,&MyReq);
  542.                         }
  543.                         
  544.                         if(Adresse==(APTR)&Gadget6)
  545.                         {
  546.                             jj=j[1]; mm=m[1]; aa=a[1];
  547.                             mmoins();
  548.                             verif();
  549.                             if(j[1]+100*m[1]+10000*a[1]<j[2]+100*m[2]+10000*a[2]) 
  550.                             {
  551.                                 j[1]=jj; m[1]=mm; a[1]=aa;
  552.                                 return(2);
  553.                             }
  554.                             else
  555.                             {
  556.                                 dates2();
  557.                                 RefreshGadgets(&Gadget3,Window,&MyReq);
  558.                             }
  559.                         }
  560.                         if(Adresse==(APTR)&Gadget7)
  561.                         {
  562.                             dates2();
  563.                             if(First)
  564.                             {
  565.                                 Gadget1.Flags=NULL;
  566.                                 Gadget5.Flags=NULL;
  567.                                 Gadget6.Flags=NULL;
  568.                             }
  569.                         }
  570.                         if(Adresse==(APTR)&Gadget1)
  571.                         {
  572.                             hardcopy();
  573.                             colors(0);
  574.                             ModifyIDCMP(Window,CLOSEWINDOW|RAWKEY|GADGETUP|REQSET|MOUSEBUTTONS);
  575.                             DMReq=SetDMRequest(Window,&MyReq);
  576.                         }
  577.                         return(1);
  578.                     }
  579.                 else
  580.                 {
  581.                     MyErr=0;
  582.                 }
  583.                 break;
  584.             case RAWKEY:
  585.                 jj=j[1]; mm=m[1]; aa=a[1];
  586.                 switch(Code)
  587.                 {
  588.                     case 206:
  589.                         if((m[1]==2 && bisex(a[1]) && j[1]==29) || (!(m[1]==2 && bisex(a[1])) && j[1]==mois[m[1]-1]))  { j[1]=0; mplus(); }
  590.                         j[1]+=1;
  591.                         return(1);
  592.                         break;
  593.                     case 207:
  594.                         if (j[1]==1)
  595.                             if(bisex(a[1]) && m[1]==3) { mmoins(); j[1]=30; }
  596.                             else { mmoins(); j[1]=mois[m[1]-1]+1; }
  597.                         j[1]-=1;
  598.                         if(j[1]+100*m[1]+10000*a[1]<j[2]+100*m[2]+10000*a[2]) 
  599.                         { 
  600.                             j[1]=jj; m[1]=mm; a[1]=aa;
  601.                             return(2);
  602.                         }
  603.                         else return(1);
  604.                         break;
  605.                     case 222:
  606.                         a[1]+=1;
  607.                         return(1);
  608.                         break;
  609.                     case 202:
  610.                         a[1]-=1;
  611.                         if(j[1]+100*m[1]+10000*a[1]<j[2]+100*m[2]+10000*a[2])
  612.                         {
  613.                             j[1]=jj; m[1]=mm; a[1]=aa;
  614.                             return(2);
  615.                         }
  616.                         else return(1);
  617.                         break;
  618.                     case 204:
  619.                         mplus();
  620.                         verif();
  621.                         return(1);
  622.                         break;
  623.                     case 205:
  624.                         mmoins();
  625.                         verif();
  626.                         if(j[1]+100*m[1]+10000*a[1]<j[2]+100*m[2]+10000*a[2]) 
  627.                         {
  628.                             j[1]=jj; m[1]=mm; a[1]=aa;
  629.                             return(2);
  630.                         }
  631.                         else return(1);
  632.                         break;    
  633.                 }
  634.                 break; 
  635.             
  636.             case CLOSEWINDOW: 
  637.                 if (DMReq) ClearDMRequest(Window);
  638.                 CloseWindow(Window);
  639.                 CloseScreen(Screen);
  640.                 CloseLibrary(GfxBase);
  641.                 CloseLibrary(IntuitionBase);
  642.                 if(DiskObj!=0) FreeDiskObject(DiskObj);
  643.                 if(IconBase!=NULL) CloseLibrary(IconBase);
  644.                 return(0);
  645.                 break;
  646.             case MOUSEBUTTONS:
  647.                 if(Code==104)
  648.                 {
  649.                     k=.5+((Window->MouseX)-10)/(lar/mois[m[1]-1]);
  650.                     j[1]=k+1;
  651.                     if (j[1]<1) j[1]=1;
  652.                     verif();
  653.                     return(1);
  654.                 }
  655.                 break;
  656.         }
  657.     }
  658.     goto wxt;
  659. }
  660.  
  661. int mplus()
  662. {
  663.         if (m[1]++==12) { m[1]=0;    a[1]+=1; }
  664.         return(0);
  665. }
  666.  
  667. int mmoins()
  668. {
  669.         if (m[1]--==1) { m[1]=13;    a[1]-=1; }
  670.         return(0);
  671. }
  672.  
  673. int sinusoide(aa,bb,c)
  674. int aa,bb,c;
  675. {
  676.     double x,xx,yy;
  677.     int i=0,xxx,yyy;
  678.     SetAPen(RPort,c+2);
  679.     xxx=sin(aa*2*pi/bb)*-amp[mode]+axe;
  680.     Move(RPort,10+(lar/mois[m[1]-1])/2,xxx);
  681.  
  682.     for( x=0; x<=2*pi*(mois[m[1]-1]-1)/bb; x=x+(2*pi/bb))
  683.     {    
  684.         xx=(.5+i++)*(lar/mois[m[1]-1])+10;
  685.         yy=(sin(x+aa*2*pi/bb))*-amp[mode]+axe;
  686.         xxx=xx;
  687.         yyy=yy;
  688.         Draw(RPort,xxx,yyy); 
  689.         Move(RPort,xxx,yyy);
  690.     } 
  691.     switch(c)
  692.     {
  693.         case 1: Text(RPort,&"P",1); break;
  694.         case 2: Text(RPort,&"C",1); break;
  695.         case 3: Text(RPort,&"E",1);
  696.     }
  697.     return(0);
  698. }
  699.  
  700. int interpretation()
  701. {
  702.     int az,ez,rz;
  703.         
  704.     if (ph[1]==0 || ph[1]==12 || ph[1]==23) az=0;
  705.     if (ph[1]<12 && ph[1]>0) az=1;
  706.     if (ph[1]>12 && ph[1]<23) az=2;
  707.     if (em[1]==0 || em[1]==14 || em[1]== 28) ez=0;
  708.     if (em[1]<14 && em[1]>0) ez=1;
  709.     if (em[1]>14 && em[1]<28) ez=2;
  710.     if (ce[1]==0 || ce[1]==16 ||ce[1]== 33) rz=0;
  711.     if (ce[1]<16 && ce[1]>0) rz=1;
  712.     if (ce[1]>16 && ce[1]<33) rz=2;
  713.     SetAPen(RPort,1);
  714.     if(strlen(inter[az][ez][rz][2])!=0)
  715.     {
  716.         Move(RPort,17,comm[mode]);
  717.         Text(RPort,inter[az][ez][rz][0],strlen(inter[az][ez][rz][0]));
  718.         Move(RPort,17,comm[mode]+comm2[mode]);
  719.         Text(RPort,inter[az][ez][rz][1],strlen(inter[az][ez][rz][1]));
  720.         Move(RPort,17,comm[mode]+2*comm2[mode]);
  721.         Text(RPort,inter[az][ez][rz][2],strlen(inter[az][ez][rz][2]));
  722.     }
  723.     else
  724.     {
  725.         Move(RPort,17,comm3[mode]);
  726.         Text(RPort,inter[az][ez][rz][0],strlen(inter[az][ez][rz][0]));
  727.         Move(RPort,17,comm3[mode]+comm2[mode]);
  728.         Text(RPort,inter[az][ez][rz][1],strlen(inter[az][ez][rz][1]));
  729.     }
  730.     return(0);    
  731. }
  732.  
  733. void ErrDev()
  734. {
  735.     BAD.IText=MyMsg;
  736.     AutoRequest(Window, &BAD, NULL, &OK, NULL, NULL, 320, 72);
  737. }
  738.  
  739. int hardcopy()
  740. {
  741.     char MyMsg[50]="";
  742.     static UBYTE *ErrorText[] =
  743.     {
  744.          "PDERR_NOERR",
  745.         "PDERR_CANCEL",
  746.         "PDERR_NOTGRAPHICS",
  747.         "INVERTHAM",        /* OBSOLETE */
  748.         "BADDIMENSION",
  749.         "DIMENSIONOVFLOW",    /* OBSOLETE */
  750.         "INTERNALMEMORY",
  751.         "BUFFERMEMORY",    
  752.         "IOERR_OPENFAIL",
  753.         "IOERR_ABORTED",
  754.         "IOERR_NOCMD",
  755.         "IOERR_BADLENGTH"
  756.     };    
  757.     struct PrinterData *PD;
  758.     BOOL STOP=TRUE;
  759.     int MyErr;
  760.     ULONG Signal;
  761.     union printerIO
  762.     {
  763.         struct IOStdReq ios;
  764.         struct IODRPReq iodrp;
  765.         struct IOPrtCmdReq iopc;
  766.     };
  767.     union printerIO *request;
  768.     struct MsgPort *printerPort;
  769.     if(DMReq)
  770.     {
  771.         ClearDMRequest(Window);
  772.         DMReq=FALSE;
  773.     }
  774.     ModifyIDCMP(Window,GADGETUP);
  775.     Request(&MyReq2,Window); 
  776.     if(printerPort=(struct MsgPort *) CreatePort("printer.port",0))
  777.     {
  778.         if(request=(union printerIO *)CreateExtIO(printerPort,sizeof(union printerIO)))
  779.         {
  780.             if(!(OpenDevice("printer.device",0,request,0)))
  781.             {
  782.                 PD=(struct PrinterData *)request->iodrp.io_Device;
  783.                 if(PD->pd_Preferences.PrintShade==0)
  784.                     colors(2);
  785.                 else
  786.                     colors(1);
  787.                 
  788.                 request->iodrp.io_Command=PRD_DUMPRPORT;
  789.                 request->iodrp.io_RastPort=RPort;
  790.                 request->iodrp.io_ColorMap=Screen->ViewPort.ColorMap;
  791.                 request->iodrp.io_Modes=NewScreen.ViewModes;
  792.                 request->iodrp.io_SrcX=6;
  793.                 request->iodrp.io_SrcY=12;
  794.                 request->iodrp.io_SrcWidth=628;
  795.                 request->iodrp.io_SrcHeight=hauteur[mode]-34;
  796.                 request->iodrp.io_DestCols=NULL;
  797.                 request->iodrp.io_DestRows=NULL;
  798.                 request->iodrp.io_Special=SPECIAL_CENTER|SPECIAL_ASPECT|SPECIAL_DENSITY7|SPECIAL_FULLCOLS;
  799.     
  800.                 SendIO(request);
  801.                 Signal=Wait(1<<Window->UserPort->mp_SigBit|1<<printerPort->mp_SigBit);
  802.                 if(Signal & (1<<Window->UserPort->mp_SigBit))
  803.                 {
  804.                     while(Message=(struct IntuiMessage *)GetMsg(Window->UserPort))
  805.                         ReplyMsg(Message);
  806.                     AbortIO(request);
  807.                       WaitIO(request);
  808.                     STOP=FALSE;
  809.                 }
  810.                 if(Signal & (1<<printerPort->mp_SigBit))
  811.                     while(GetMsg(printerPort));
  812.                 if(request->iodrp.io_Error !=0)
  813.                 {
  814.                     MyErr =request->iodrp.io_Error;
  815.                             if (MyErr < 0) MyErr=MyErr*-1 +7;
  816.                     sprintf(MyMsg,"Erreur : %s",ErrorText[MyErr]);
  817.                     BAD.IText=MyMsg;
  818.                     if(MyErr!=9) AutoRequest(Window, &BAD, NULL, &OK, NULL, NULL, 320, 72);
  819.                 }
  820.                 CloseDevice((struct IORequest*)request);
  821.             }
  822.             else ErrDev();
  823.             
  824.             DeleteExtIO((struct IORequest*)request);
  825.         }
  826.         else    ErrDev();
  827.         DeletePort(printerPort);
  828.         if(STOP) EndRequest(&MyReq2,Window);
  829.     }
  830.     return(0);
  831. }